package com.netty.in_outboundhander;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class MyServer_Hander extends SimpleChannelInboundHandler<Long> {
    //处理接收的消息
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("收到的消息是: "+msg +"地址是: "+ctx.channel().remoteAddress());
        //给客户端发送一个long
        //ctx.writeAndFlush(98765L);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(987654321L);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.channel().close();
    }
}
